package hl.service.impl;

import java.math.BigDecimal;
import java.util.Date;
import java.util.UUID;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import hl.dao.BaseDao;
import hl.model.TMenu;
import hl.model.TPcOperator;
import hl.model.TStuff;
import hl.pageModel.PcOperator;
import hl.service.RepairService;
import hl.util.Encrypt;

@Service("repairService")
public class RepairServiceImpl implements RepairService{

	private static final Logger logger = Logger.getLogger(RepairServiceImpl.class);


	
	private BaseDao<TMenu> menuDao;

	private BaseDao<TPcOperator> PcOperatorDao;
	
	private BaseDao<TStuff> stuffDao;
	
	
	
	public BaseDao<TStuff> getStuffDao() {
		return stuffDao;
	}

	@Autowired
	public void setStuffDao(BaseDao<TStuff> stuffDao) {
		this.stuffDao = stuffDao;
	}


	public BaseDao<TPcOperator> getUserDao() {
		return PcOperatorDao;
	}
	
	
	public BaseDao<TMenu> getMenuDao() {
		return menuDao;
	}

	@Autowired
	public void setMenuDao(BaseDao<TMenu> menuDao) {
		this.menuDao = menuDao;
	}


	public BaseDao<TPcOperator> getPcOperatorDao() {
		return PcOperatorDao;
	}

	@Autowired
	public void setPcOperatorDao(BaseDao<TPcOperator> pcOperatorDao) {
		PcOperatorDao = pcOperatorDao;
	}


	@Override
	public void repair() {
//		repairMenu();
//		repairUser();
	}
	
	private void repairUser() {
		TPcOperator user=PcOperatorDao.get("from TPcOperator where account='admin' and pkPcOperator!='1800000001' ");
		if(user!=null) {
			user.setAccount((UUID.randomUUID().toString()));
		}
		TPcOperator admin = PcOperatorDao.get(TPcOperator.class,new Long(1800000001L));
		admin.setAccount("admin");
		admin.setPassword(Encrypt.e("admin"));
		admin.setTStuff(stuffDao.get(TStuff.class, new Long(7883300001L)));
		admin.setMdatetime(new Date());
		PcOperatorDao.saveOrUpdate(admin);
	}

	private void repairMenu() {
		TMenu root = new TMenu();
		root.setPkMenu("000");
		root.setText("首页");
		
		menuDao.saveOrUpdate(root);
		
		TMenu jsgl = new TMenu();
		jsgl.setPkMenu("001");
		jsgl.setText("健身服务");
		menuDao.saveOrUpdate(jsgl);
		
		TMenu tkgl = new TMenu();
		tkgl.setPkMenu("0011");
		tkgl.setTMenu(jsgl);
		tkgl.setText("团课");
		tkgl.setUrl("fitSerMgt/groupCourseMgt.jsp");
		menuDao.saveOrUpdate(tkgl);
		
		
		TMenu skgl = new TMenu();
		skgl.setPkMenu("0012");
		skgl.setTMenu(jsgl);
		skgl.setText("私教");
		menuDao.saveOrUpdate(skgl);
		
		TMenu kcgl = new TMenu();
		kcgl.setPkMenu("0013");
		kcgl.setTMenu(jsgl);
		kcgl.setText("课程");
		kcgl.setUrl("fitSerMgt/courseDetailMgt.jsp");
		menuDao.saveOrUpdate(kcgl);
		
		TMenu rcqd = new TMenu();
		rcqd.setPkMenu("0014");
		rcqd.setTMenu(jsgl);
		rcqd.setText("签场");
		rcqd.setUrl("fitSerMgt/signMgt.jsp");
		menuDao.saveOrUpdate(rcqd);
		
		TMenu hygl = new TMenu();
		hygl.setPkMenu("002");
		hygl.setText("会员管理");
		menuDao.saveOrUpdate(hygl);
		
		TMenu higl = new TMenu();
		higl.setPkMenu("0021");
		higl.setTMenu(hygl);
		higl.setText("会员信息");
		higl.setUrl("memberMgt/memberMgt.jsp");
		menuDao.saveOrUpdate(higl);
		
		TMenu hipgl = new TMenu();
		hipgl.setPkMenu("00211");
		hipgl.setTMenu(higl);
		hipgl.setText("会员体测信息");
		menuDao.saveOrUpdate(hipgl);
		
		TMenu hcgl = new TMenu();
		hcgl.setPkMenu("0022");
		hcgl.setTMenu(hygl);
		hcgl.setText("会员卡");
		menuDao.saveOrUpdate(hcgl);
		
		TMenu yggl = new TMenu();
		yggl.setPkMenu("003");
		yggl.setText("员工管理");
		menuDao.saveOrUpdate(yggl);
		
		TMenu grgl = new TMenu();
		grgl.setPkMenu("0031");
		grgl.setTMenu(yggl);
		grgl.setText("工作人员");
		grgl.setUrl("staffMgt/stuffMgt.jsp");
		menuDao.saveOrUpdate(grgl);
		
		TMenu jlgl = new TMenu();
		jlgl.setPkMenu("0032");
		jlgl.setTMenu(yggl);
		jlgl.setText("教练");
		jlgl.setUrl("staffMgt/coachMgt.jsp");
		menuDao.saveOrUpdate(jlgl);
		
		TMenu cggl = new TMenu();
		cggl.setPkMenu("004");
		cggl.setText("场馆管理");
		menuDao.saveOrUpdate(cggl);
		
		TMenu cigl = new TMenu();
		cigl.setPkMenu("0041");
		cigl.setTMenu(cggl);
		cigl.setText("场馆信息");
		cigl.setUrl("venueMgt/venueInfoMgt.jsp");
		menuDao.saveOrUpdate(cigl);
		
		TMenu cdigl = new TMenu();
		cdigl.setPkMenu("0042");
		cdigl.setTMenu(cggl);
		cdigl.setText("场地");
		cdigl.setUrl("venueMgt/placeMgt.jsp");
		menuDao.saveOrUpdate(cdigl);
		
		TMenu zcgl = new TMenu();
		zcgl.setPkMenu("0043");
		zcgl.setTMenu(cggl);
		zcgl.setText("资产");
		menuDao.saveOrUpdate(zcgl);
		
		TMenu wxgl = new TMenu();
		wxgl.setPkMenu("0044");
		wxgl.setTMenu(cggl);
		wxgl.setText("小程序信息");
		menuDao.saveOrUpdate(wxgl);
		
		TMenu cwgl = new TMenu();
		cwgl.setPkMenu("005");
		cwgl.setText("财务管理");
		menuDao.saveOrUpdate(cwgl);
		
		TMenu kcbb = new TMenu();
		kcbb.setPkMenu("0051");
		kcbb.setTMenu(cwgl);
		kcbb.setText("课程报表");
		menuDao.saveOrUpdate(kcbb);
		
		TMenu xsbb = new TMenu();
		xsbb.setPkMenu("0052");
		xsbb.setTMenu(cwgl);
		xsbb.setText("销售报表");
		menuDao.saveOrUpdate(xsbb);
		
		TMenu gzgl = new TMenu();
		gzgl.setPkMenu("0053");
		gzgl.setTMenu(cwgl);
		gzgl.setText("工资管理");
		menuDao.saveOrUpdate(gzgl);
		
		TMenu xxgl = new TMenu();
		xxgl.setPkMenu("006");
		xxgl.setText("系统管理");
		menuDao.saveOrUpdate(xxgl);
		
		TMenu cdgl = new TMenu();
		cdgl.setPkMenu("0061");
		cdgl.setTMenu(xxgl);
		cdgl.setText("菜单");
		cdgl.setUrl("sysMgt/menuMgt.jsp");
		menuDao.saveOrUpdate(cdgl);
	}

}
